# 公用工具类
import functools

from flask import session, g


def do_index_class(index):
    '''返回指定索引对应的类名'''
    if index == 0:
        return 'first'
    if index == 1:
        return 'second'
    if index == 2:
        return 'third'
    return ''


# 装饰器函数
def user_login_data(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        # 获取到当前登录用户的id
        user_id = session.get("user_id")
        # 通过id获取用户信息
        user = None
        if user_id:
            from web_.models import User
            user = User.query.get(user_id)
        g.user = user
        return f(*args, **kwargs)
    return wrapper
